<template>
  <v-card
    :title="tag == 1 ? '在途车辆动态信息' : '在途火车动态信息'"
    bgImg="https://oss.sdland-sea.com/group2/M01/16/06/Cof8E2IxgOCAYlXeAACSfyrQms0977.png"
  >
    <div class="card-container">
      <div class="list-header">
        <div class="checi" v-if="tag == 2">车次</div>
        <div class="gangkou">港口</div>
        <!-- :class="{ qiyun: tag == 1 }" -->
        <div class="gangqu" :class="{ train: tag == 2 }">港区</div>
        <div class="cheliang">车辆状态</div>
        <!-- :class="{ qiyun: tag == 1 }" -->
        <div class="yudi">预抵时间</div>
        <!-- v-if="tag !== 1" -->
        <div class="yunshu">运输时长</div>
        <div class="chepaihao" v-if="tag == 1">
          车牌号
        </div>
        <div class="mudidi" v-if="tag == 1">司机</div>
        <div class="huoming">货物名称</div>
        <div class="pizhong">
          {{ tag == 1 ? "入港皮重(t)" : "装货标重(t)" }}
        </div>
        <div class="maozhong">
          {{ tag == 1 ? "出港毛重(t)" : "出港净重(t)" }}
        </div>
        <!-- <div class="jingzhong">净重</div>
        <div class="huosun">货损</div> -->
      </div>
      <div class="list-body">
        <div :id="id" class="swiper mySwiperCont" @click="handleParentClick">
          <div
            class="swiper-wrapper"
            :class="{ flexSwiperWrapper: listData.length < maxLength }"
          >
            <div
              class="swiper-slide"
              v-for="(item, index) in listData"
              :key="index"
              :data-index="index"
            >
              <div class="list-item" :data-index="index">
                <div v-if="tag == 2" class="checi">
                  {{ item.sequence || "未知" }}
                </div>
                <div class="gangkou">{{ item.port || "未知" }}</div>
                <!-- :class="{ qiyun: tag == 1 }" -->
                <div class="gangqu" :class="{ train: tag == 2 }">
                  {{ item.portArea || "未知" }}
                </div>
                <div class="cheliang">{{ item.carStatus || "未知" }}</div>
                <!-- :class="{ qiyun: tag == 1 }" -->
                <div class="yudi">
                  {{ item.estimateTime || "未知" }}
                </div>
                <!-- v-if="tag !== 1" -->
                <div class="yunshu">
                  {{ (tag == 1 ? item.roadTime : item.transportLen) || 0 }} h
                </div>
                <div class="chepaihao" v-if="tag == 1">
                  {{ item.carNo || "未知" }}
                </div>
                <div class="mudidi" v-if="tag == 1">
                  {{ item.driver || "未知" }}
                </div>
                <div class="huoming">{{ item.cargoName }}</div>
                <div class="pizhong">{{ item.tareWeight }}</div>
                <div class="maozhong">{{ item.grossWeight }}</div>
                <!-- <div class="jingzhong">48.66</div>
                <div class="huosun">0</div> -->
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </v-card>
</template>

<script>
import MIXIN from "./mxin";
import { getPortTransportInfo } from "@/api/networShow/dataV";

// 数据
export default {
  mixins: [MIXIN],
  data() {
    return {
      id: "portTransportInfo",
      maxLength: 4
    };
  },
  computed: {
    pointTruck() {
      return {
        centerMapOnload: this.centerMapOnload,
        tag: this.tag,
        listData: this.listData
      };
    }
  },
  watch: {
    pointTruck: {
      deep: true,
      handler(newVal) {
        const { centerMapOnload, tag, listData } = newVal;
        if (centerMapOnload && tag == 1 && listData.length) {
          this.centerMap.addTruck(this.listData);
        }
      }
    }
  },
  methods: {
    async getListData() {
      this.listData = []; // 处理因数据不一致导致的页面错乱的情况
      const { data } = await getPortTransportInfo(this.tag);
      if (data.code == 200) {
        this.listData = data.data;
        if (this.centerMapOnload) {
          this.centerMap.resetMap();
          this.centerMap.clearTruck();
        }
        if (this.tag == 1) {
          this.$store.commit("dataV/UPDATE_TRUCKJSON", this.listData);
        }
      }
    },

    handleMap(index) {
      if (this.tag != 1) {
        return;
      }
      this.centerMap.addDefaultPort();
      // 移除 精品线路
      this.centerMap.clearLine();
      // 移除 精品线路点
      this.centerMap.clearStartEndPoint();
      if (this.hanlder == "truck_portPlan") {
        this.$store.commit("dataV/UPDATE_HANLDER", "truck_portTransport"); // 更新与操作
        this.centerMap.clearTruck();
      }
      this.centerMap.addTruck(this.truckjson);
      const item = this.listData[index];
      const geojsonItem = this.centerMap.generateGeojsonItem(item);
      this.centerMap.setPopupTruck(geojsonItem); // this.centerMap.map
    }
  },
  mounted() {
    this.getListData();
  }
};
</script>

<style lang="less" scoped>
.card-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .list-header,
  .list-item {
    cursor: pointer;
    width: 100%;
    display: flex;
    height: 22px;
    line-height: 22px;
    background: rgba(216, 216, 216, 0.25);
    font-size: 12px;
    font-family: SourceHanSansCN-Bold, SourceHanSansCN;
    font-weight: bold;
    color: #ffffff;
    display: flex;
    cursor: pointer;
    & > div {
      // white-space: nowrap;
      // overflow: hidden;
      // text-overflow: ellipsis;
      padding: 0 2px;
      box-sizing: border-box;
    }
    .checi {
      width: 95px;
    }
    .gangkou {
      width: 45px;
    }
    .gangqu {
      // &.train {
      width: 55px;
      // }
      // width: 43px;
    }
    .cheliang {
      width: 55px;
    }
    .mudidi {
      width: 45px;
    }
    .yudi {
      &.qiyun {
        width: 90px;
      }
      width: 80px;
    }
    .yunshu {
      width: 55px;
    }
    .chepaihao {
      width: 65px;
    }
    .huoming {
      width: 52px;
    }
    .pizhong {
      // width: 37px;
      flex: 1;
    }
    .maozhong {
      // width: 37px;
      flex: 1;
    }
  }
  .list-body {
    flex: 1;
    .flexSwiperWrapper {
      display: flex;
      flex-direction: column;
      .swiper-slide {
        height: 44px;
        line-height: 44px;
      }
    }
    .mySwiperCont {
      height: 180px;
      .swiper-slide {
        &:nth-child(odd) {
          .list-item {
            background: transparent;
          }
        }
        &:nth-child(even) {
          .list-item {
            background: rgba(56, 64, 138, 0.25);
          }
        }
      }
    }
    .list-item {
      // padding: 3px 0;
      // height: auto;
      // line-height: 34px;
      align-items: center; /*实现水平居中*/
      height: 100%;
    }
  }
}
</style>
